<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4989 2010-08-26 04:14:28Z huuphuoc $
 * @since		2.0.0
 */
?>
<?php 
$this->headTitle($this->translator('file_list_page_title'));

$this->headLink()
	->appendStylesheet($this->APP_STATIC_SERVER . '/skins/admin/default/css/filelist.css');

//$this->headScript()
//	->appendFile($this->APP_STATIC_SERVER . '/public/js/jquery.min.js');
?>
<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/article.png'; ?>" alt=""/>
    <span><?php echo $this->translate('file_list_breadcrumb') ?></span>
    <input type="button" id="btnCreate" class="button" value="<?php echo $this->translate('permission_file_add'); ?>" onclick="location = '<?php echo $this->url(array(), 'multimedia_file_add'); ?>';"/>
</div>
<?php
$massage = $this->flashMessenger();
if ($massage) {
    ?>
    <div id="message"><?php echo $massage; ?></div>
<?php } ?>

<!--<div class="grid_12 t_a_bottom">
	<div class="grid_8 alpha"><?php echo $this->translator('file_list_guide'); ?></div>
	<div class="grid_4 omega">
		<div class="t_a_right">
			<a style="margin: 0 10px" class="t_a_ui_button_link" href="<?php echo $this->url(array(), 'multimedia_photo_upload'); ?>"><span><?php echo $this->translator('photo_upload_breadcrumb'); ?></span></a> <a class="t_a_ui_button_link" href="<?php echo $this->url(array(), 'multimedia_file_add'); ?>"><span><?php echo $this->translator('file_add_breadcrumb'); ?></span></a>
		</div>
	</div>	
</div>-->

<!-- Search form -->
<form method="post" action="<?php echo $this->url(array(), 'multimedia_file_list'); ?>" id="searchFileForm">
    <div id="filters">
        <div class="f-data">
            <label><?php echo $this->translator('file_list_search_keyword'); ?>:</label>
            <input type="text" style="width: 300px" name="keyword" value="<?php if (isset($this->exp['keyword'])) : ?><?php echo $this->exp['keyword']; ?><?php endif; ?>" />
        </div>
        <div class="f-data">
            <label><?php echo $this->translator('file_list_search_id'); ?>:</label>
            <input type="text" style="width: 100px" name="fileId" id="fileId" value="<?php if (isset($this->exp['id'])) : ?><?php echo $this->exp['id']; ?><?php endif; ?>" />
        </div>
        <div class="f-data">
            <label><?php echo $this->translator('file_list_search_file_type')?></label>
            <?php
                echo isset($this->exp['file_type']) ?
                     $this->fileTypeSelect(array('name' => 'file_type', 'id'=>'file_type', 'selected' => $this->exp['file_type']))
                : $this->fileTypeSelect(array('name' => 'file_type', 'id'=>'file_type'));
                
            ?>
            
        </div>
        <div class="f-data">
            <input type="checkbox" name="findMyFiles"<?php if (isset($this->exp['created_user_id'])) : ?> checked="checked"<?php endif; ?> value="1" /> <?php echo $this->translator('file_list_search_my_files'); ?>
        </div>
        <div class="f-submit">
            <input type="submit" class="button" value="<?php echo $this->translate('file_list_search_button'); ?>" />
        </div>
    </div>    
</form>

<!-- List of files -->
<?php if ($this->numFiles == 0) : ?>
	<div class="grid_12 t_a_bottom"><?php echo $this->translator('file_list_not_found'); ?></div>	
<?php else : ?>	
        <ul id ="fileList">
        <?php foreach ($this->files as $index => $file) : ?>
            <li id="fileRow_<?php echo $file->id; ?>" >
			<div>
                            <?php if ($file->file_type == 'image') :?>
                            <div class="image">
                                <img align="center" alt="<?php echo $file->image_altertext?>" src="<?php echo $file->image_small; ?>" />
                            </div>    
                            <?php else: ?>
                            <div class="file <?php echo $file->file_type?>">
                                <?php echo substr($file->url, strrpos($file->url, '/') + 1) ?>
                            </div>    
                            <?php endif;?>
                        </div>
			
			<div class="clearfix file_title"><?php echo $file->title; ?></div>
			<div class="file_description clearfix"><?php echo $file->description; ?></div>
			
			<div class="file_action">
				<?php if ($this->allow('edit')) : ?>
				<a href="<?php echo $this->url(array('id' => $file->id), 'multimedia_file_edit'); ?>"><?php echo $this->translator('file_list_action_edit'); ?></a> |
				<?php endif; ?>
				
				<?php if ($this->allow('delete')) : ?> 
				<a class="deleteAction" rel="<?php echo $file->id; ?>" href=""><?php echo $this->translator('file_list_action_delete'); ?></a> |
				<?php endif; ?>
				
				<?php if ($this->allow('activate')) : ?>
				 <a class="activateAction" rel="<?php echo $file->id ?>_<?php echo (int)$file->actived; ?>_<?php echo $file->slug; ?>" href="javascript: void(0);"><?php if ($file->actived) : ?><?php echo $this->translator('file_list_action_deactivate'); ?><?php else : ?><?php echo $this->translator('file_list_action_activate'); ?><?php endif; ?></a>
				<?php endif; ?>
			</div>
            </li>
            <?php if($index > 0 && ($index + 1) % 4 == 0) :?>
            <li class="clearfix separator"></li>
            <?php endif?>
        <?php endforeach; ?>
        </ul>
	<div id="pagination">
        <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
        </div>
	
<?php endif; ?>

<script type="text/javascript">
$(document).ready(function() {
	
	<?php if ($this->allow('delete')) : ?>
	$('a.deleteAction').click(function() {
                if(confirm('<?php echo addslashes($this->translator('file_list_action_delete_confirm'));?>')){
                    var id = $(this).attr('rel');
                    $.ajax({
                                type: 'POST',
                                url: "<?php echo $this->url(array(), 'multimedia_file_delete'); ?>",
                                data: { id: id },
                                dataType: 'json',
                                success: function(response) {
                                    if (response.status) {
                                        $('#fileRow_' + id).fadeOut('slow', function(){$(this).remove()});
                                    }
                                }
                            });    
                }
		return false;
	});
	<?php endif; ?>

	<?php if ($this->allow('activate')) : ?>
	$('a.activateAction').click(function() {
		var arr = $(this).attr('rel').split('_');
		$(this).html('').addClass('loading-inline');
                var self = this;
		$.ajax({
			url: "<?php echo $this->url(array(), 'multimedia_file_activate'); ?>",
			type: 'POST',
			data: { id: arr[0], status: arr[1] },
			success: function(response) {
				$(self).attr('rel', arr[0] + '_' + response + '_' + arr[2]);
				if (response == 1) {
					$(self).html("<?php echo $this->translator('file_list_action_deactivate'); ?>");
				} else {
					$(self).html("<?php echo $this->translator('file_list_action_activate'); ?>");
				}
				$(self).removeClass('loading-inline').fadeIn('normal');
			}
		});
	});
	<?php endif; ?>


	/**
	 * Validate search form
	 */
//	$('#searchFileForm').validate({
//		rules: {		
//			fileId: {
//				number: true
//			}
//	    },
//	    messages: {
//	    	fileId: {
//	        	number: "<?php echo $this->translator('file_list_id_invalid'); ?>"
//			}
//		}
//	});
});
</script>
